/**
 * 
 */
package com.ykdl.member.base;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.telephony.TelephonyManager;

import com.ykdl.member.constant.KidAction;

/**
 * @author yuangg
 * @date Dec 8, 2011
 * @time 10:52:57 AM
 * 放置连接服务器的地址，图片地址等
 */
public class GlobalContext {
	public static Context mContext;
	// private static ProgressDialog mProgressDialog;
	// private static LayoutInflater mLayoutInflater;

	private static TelephonyManager mTelephonyManager;
//	private static SmsManager mSMSManager;

	private static String mDeviceID;

	private static Properties mConfig;
	public static String PROJECT_SERVER;//请求地址，个人头像，
	public static String DOWNLOAD_URI;//官网下载页面
	
	
	private static String mVersionCode;
	//查看工具上传的图片
	public static void init(Context ctx) {
		if (mContext == null) {
			mContext = ctx.getApplicationContext();
			// mLayoutInflater = (LayoutInflater) mContext
			// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			// mProgressDialog = new ProgressDialog(mContext);
			// mProgressDialog.setTitle(null);
			// mProgressDialog.setMessage("加载中。。。");
			// mProgressDialog.setIndeterminate(true);
			// mProgressDialog.setCancelable(false);

			mTelephonyManager = (TelephonyManager) mContext
					.getSystemService(Context.TELEPHONY_SERVICE);
			mDeviceID = mTelephonyManager.getDeviceId();
	
		//	mSMSManager = SmsManager.getDefault();

			mConfig = new Properties();
			try {
				mConfig.load(mContext.getAssets().open("server.properties"));
				PROJECT_SERVER = mConfig.getProperty("server").trim();
				QLog.debug("PROJECT_SERVER from props: " + PROJECT_SERVER);
				// CONTENT_SERVER = PROJECT_SERVER + "/magnoliaPublic";
				DOWNLOAD_URI = mConfig.getProperty("download").trim();
				QLog.debug("DOWNLOAD_URI from props: " + DOWNLOAD_URI);
				
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			
			try {
				mVersionCode =""+ mContext.getPackageManager().getPackageInfo(
						mContext.getPackageName(), 0).versionCode;
			} catch (NameNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public static InputStream getAssetsStream(String cert) {
		try {
			return mContext.getAssets().open(cert);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}

	public static void sendBroadcast(String action) {
		mContext.sendBroadcast(new Intent(action));
	}

	public static void exit() {
		mContext.sendBroadcast(new Intent(KidAction.EXIT));
	}

	// public static View inflateLayout(int layout, ViewGroup root) {
	// return mLayoutInflater.inflate(layout, root);
	// }

	// public static void showProgress() {
	// // ProgressDialog.show(mContext, "", "加载中。。。", true, false);
	// mProgressDialog.show();
	// }
	//
	// public static void finishProgress() {
	// mProgressDialog.hide();
	// }

	public static String getDeviceID() {
		return mDeviceID;
	}

	public static String getVersionCode() {
		return mVersionCode;
	}

//	public static void sendSMS(String number, String content) {
//		mSMSManager.sendTextMessage(number, null, content, null, null);
//	}
}
